package com.taikang.t.service.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taikang.common.util.hibernate.SimpleHibernateTemplate;
import com.taikang.t.model.RandomWord;

@Service
public class RandomWordManager {

	
	private SimpleHibernateTemplate<RandomWord, Long> randomWordDAO;
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		randomWordDAO = new SimpleHibernateTemplate<RandomWord, Long>(sessionFactory, RandomWord.class);
	}
	
	
	@SuppressWarnings("unchecked")
	public List findAnswers()
	{
		return randomWordDAO.findAll();
	}
	
	public String findAnswer()
	{
		RandomWord fw = (RandomWord) randomWordDAO.findUniqueByNativeSql("select * from Random_Word order by rand() fetch first 1 rows only"); 
		return fw.getAnswer();
	}
	
}
